package ggplinko

import (
	"github.com/shopspring/decimal"
	"wzgames/internal/model/gkindp"
	"wzgames/internal/secure/rng"
)

type Gift struct {
}

func (gf *Gift) Init(cfg *gkindp.PlinkoConfig) {

}

func (gf *Gift) Update(cfg *gkindp.PlinkoConfig) {

}

func (gf *Gift) Calculate(servSeed, clientSeed string, selPins int32) int32 {
	total := (3+selPins)*2 - 1
	middle := total/2 + 1
	pins := int(selPins)
	nums := rng.CalculateHash(servSeed, clientSeed, rng.ChunkSize, pins)
	direction := decimal.NewFromInt32(2)
	for i := 0; i < pins; i++ {
		v1 := decimal.NewFromFloat(nums[i]).Mul(direction)
		dir := int32(v1.IntPart())
		if dir == 0 {
			middle += -1
		} else {
			middle += 1
		}
	}
	middle = middle/2 - 1

	return middle
}
